﻿// ***********************************************************************
// Assembly         : Zf3DPlatform.Project
// Author           : tianteng
// Created          : 03-16-2018
//
// Last Modified By : tianteng
// Last Modified On : 03-16-2018
// ***********************************************************************
// <copyright file="ProjectDeleteCmd.cs" company="北京智帆高科科技有限公司">
//     Copyright ©  2017
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Windows.Forms;
using OSS.BIM.Business;
using OSS.BIM.Business.Utility;
using OSS.BIM.Model;
using OSS.BIM.Utility;
using ZFGK.Addins;
using ZFGK.Utility;

namespace OSS.BIM.Commands.ProjcetCmds
{
    /// <summary>
    /// Class ProjectDeleteCmd.
    /// </summary>
    /// <seealso cref="ZFGK.Addins.IExtendCommand" />
    public class ProjectDeleteCmd : IExtendCommand
    {
        /// <summary>
        /// Executes the specified command data.
        /// </summary>
        /// <param name="cmdData">The command data.</param>
        /// <param name="message">The message.</param>
        /// <returns>CmdResult.</returns>
        public CmdResult Execute(ExtendCmdData cmdData, ref string message)
        {
            var userProject = cmdData.Tag as Project;
            if (userProject == null)
                userProject = CurUserGroup.Instance.Project;
            if (userProject == null)
            {
                ZfMessageUtil.ShowError("当前分组为空!");
                return CmdResult.Cancel;
            }
            if (CurUserGroup.Instance.Project != null && userProject.ProjectId == CurUserGroup.Instance.Project.ProjectId)
            {
                ZfMessageUtil.ShowWarning("当前活动项目不能删除！");
                return CmdResult.Cancel;
            }
            if (MessageBox.Show("确认要删除该项目?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
            {
                return CmdResult.Cancel;
            }

            if (!ProjectDbUtil.Delete(userProject))
            {
                ZfMessageUtil.ShowError("更新数据库失败!", "数据库错误");
                return CmdResult.Cancel;
            }
            userProject.DeleteTreeNode();

            return CmdResult.Succeed;  
        }
    }
}
